package com.freejy.ecommunity.common.jackson;

import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
import com.fasterxml.jackson.databind.ser.SerializerFactory;

/**
 * @author Jerry
 */
public class CustomSerializeProvider extends DefaultSerializerProvider
{

	private static final long serialVersionUID = 7430732132436131850L;

	public CustomSerializeProvider() {
        super();
    }

    public CustomSerializeProvider(CustomSerializeProvider provider, SerializationConfig config, SerializerFactory jsf) {
        super(provider, config, jsf);
    }

    @Override
    public CustomSerializeProvider createInstance(SerializationConfig config, SerializerFactory jsf) {
        return new CustomSerializeProvider(this, config, jsf);
    }

    @Override
    public JsonSerializer<Object> findNullValueSerializer(BeanProperty property) throws JsonMappingException {
        if (property.getType().getRawClass().equals(String.class))
            return CustomSerializa.EMPTY_STRING_SERIALIZER_INSTANCE;
        else
            return super.findNullValueSerializer(property);
    }

}
